package algebra.op;


import algebra.ProjectionDescription;

/**
 * A special query (C, Pd)
 * @author j55wu
 *
 */
public class InformativeObjectQuery extends ProjectionQuery{

	private Query sub;
	private ProjectionDescription pd;
	
	public InformativeObjectQuery(ProjectionDescription pd, Query sub) {
		super(pd, sub);
		this.sub = sub;
		this.pd = pd;
	}
	
	public Query getSelectionCondition(){
		return this.sub;
	}
	
	//translate into an algebraic expression
	public ProjectionQuery translate() throws Exception{
		ProjectionQuery pq = null;
		if(sub instanceof CQuery){
			pq = new ProjectionQuery(pd, new SelectionQuery(new PQuery(), 
					((CQuery)sub).getQueryCocnept()));
		}else{
			throw new Exception("Projection queries can be translated only if the " +
					"subquery is a CONCEPT, but the supplied one is "
					+ this.sub);
		}
		return pq;
	}
	
	@Override
	public boolean isPure() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return "("+" "+this.sub.toString()+", ["+this.pd.toString()+"] )";
	}

	
	
}
